package com.spic.business.plan.report.service.impl;

import com.spic.business.common.datascope.anotation.BusinessDataScope;
import com.spic.business.plan.report.domain.PlanGreatItemsReport;
import com.spic.business.plan.report.mapper.PlanGreatItemsReportMapper;
import com.spic.business.plan.report.service.IPlanGreatItemsReportService;
import com.spic.common.core.domain.R;
import com.spic.common.core.utils.DateUtils;
import com.spic.system.api.RemoteUserService;
import com.spic.system.api.domain.SysDept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 重大事项报告Service业务层处理
 *
 * @author spic
 * @date 2021-10-15
 */
@Service
public class PlanGreatItemsReportServiceImpl implements IPlanGreatItemsReportService
{
    @Autowired
    private PlanGreatItemsReportMapper planGreatItemsReportMapper;

    @Autowired
    private RemoteUserService remoteUserService;
    /**
     * 查询重大事项报告
     *
     * @param id 重大事项报告主键
     * @return 重大事项报告
     */
    @Override
    public PlanGreatItemsReport selectPlanGreatItemsReportById(String id)
    {
        return planGreatItemsReportMapper.selectPlanGreatItemsReportById(id);
    }

    /**
     * 查询重大事项报告列表
     *
     * @param planGreatItemsReport 重大事项报告
     * @return 重大事项报告
     */
    @Override
    @BusinessDataScope(menuPath = "business/plan/report/index")
    public List<PlanGreatItemsReport> selectPlanGreatItemsReportList(PlanGreatItemsReport planGreatItemsReport)
    {
        List<PlanGreatItemsReport> PlanGreatItemsReportList = planGreatItemsReportMapper.selectPlanGreatItemsReportList(planGreatItemsReport);
        PlanGreatItemsReportList.forEach(deptList -> {
            String workUnit = deptList.getSubmitDepartment();
            Long deadline = Long.parseLong(workUnit);
            R<SysDept> sysDept1 = remoteUserService.lists(deadline);
            if (sysDept1.getData() != null) {
                deptList.setSubmitDepartment(sysDept1.getData().getDeptName());
            }

        });
        return PlanGreatItemsReportList;
    }

    /**
     * 新增重大事项报告
     *
     * @param planGreatItemsReport 重大事项报告
     * @return 结果
     */
    @Override
    public int insertPlanGreatItemsReport(PlanGreatItemsReport planGreatItemsReport)
    {
        planGreatItemsReport.setCreateTime(DateUtils.getNowDate());
        return planGreatItemsReportMapper.insertPlanGreatItemsReport(planGreatItemsReport);
    }

    /**
     * 修改重大事项报告
     *
     * @param planGreatItemsReport 重大事项报告
     * @return 结果
     */
    @Override
    public int updatePlanGreatItemsReport(PlanGreatItemsReport planGreatItemsReport)
    {
        planGreatItemsReport.setUpdateTime(DateUtils.getNowDate());
        return planGreatItemsReportMapper.updatePlanGreatItemsReport(planGreatItemsReport);
    }

    /**
     * 批量删除重大事项报告
     *
     * @param ids 需要删除的重大事项报告主键
     * @return 结果
     */
    @Override
    public int deletePlanGreatItemsReportByIds(String[] ids)
    {
        return planGreatItemsReportMapper.deletePlanGreatItemsReportByIds(ids);
    }

    /**
     * 删除重大事项报告信息
     *
     * @param id 重大事项报告主键
     * @return 结果
     */
    @Override
    public int deletePlanGreatItemsReportById(String id)
    {
        return planGreatItemsReportMapper.deletePlanGreatItemsReportById(id);
    }
}
